<?php
/**
 * Soar Framework - Lightweight and simple to use PHP Framework
 *
 * Soar is free software and is distributed WITHOUT ANY WARRANTY
 *
 * @package Soar
 * @version 1.0 $Id: SoarRegistry.php 2 2012-04-06 21:50:33Z shay@shayanderson.com $
 * @copyright Copyright (c) 2012 ShayAnderson.com
 * @license http://www.gnu.org/licenses/gpl.html GPL License
 * @link http://www.shayanderson.com/projects/soar-php-framework.htm
 */

/**
 * Soar Framework Registry Class
 *
 * @package Soar
 * @name SoarRegistry
 * @author Shay Anderson 4.12
 *
 * @example
 * $registry = new SoarRegistry();
 * $registry->param1 = 'value1';
 * echo $registry->param1;
 * $registry->obj = new SoarRegistry();
 * $registry->obj->param1 = 'value1';
 * echo $registry->obj->param1;
 */
class SoarRegistry
{
	/**
	 * Registry
	 *
	 * @var array ('key' => 'value', [, ...])
	 */
	protected $_reg = array();

	/**
	 * Registry value getter by key
	 *
	 * @param string $key
	 * @return mixed
	 */
	public function __get($key)
	{
		if($this->__isset($key))
		{
			return $this->_reg[$key];
		}
		return NULL;
	}

	/**
	 * Check if registry key exists
	 *
	 * @param string $key
	 * @return bool
	 */
	public function __isset($key)
	{
		return isset($this->_reg[$key]);
	}

	/**
	 * Registry value setter by key
	 *
	 * @param string|array $key
	 * @param mixed $value
	 */
	public function __set($key, $value)
	{
		if(is_array($key))
		{
			foreach($key as $k => $v)
			{
				$this->_reg[$k] = $v;
			}
		}
		else
		{
			$this->_reg[$key] = $value;
		}
	}

	/**
	 * Unset registry value by key
	 *
	 * @param string $key
	 */
	public function __unset($key)
	{
		if($this->__isset($key))
		{
			unset($this->_reg[$key]);
		}
	}
}
?>